<?php
class User_Service_Department 
{

	public static function getByCondition($condition,$type='*',$order, $pageSize=0, $page=1)
	{ 
		$obj=new User_Model_Department();
		$rows= $obj->getByCondition( $condition,$type,$order, $pageSize,$page);	
		return $rows;
	}

	public static function getAll()
	{ 
		$obj=new User_Model_Department();
		$rows= $obj->getSelect();
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}	
	
	public static function getById($ud_id)
	{ 
		$obj=new User_Model_Department();
		$rows=$obj->getById($ud_id);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}

	public static function getByName($ud_name)
	{ 
		$obj=new User_Model_Department();
		$rows=$obj->getByName($ud_name);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}
	
	public static function getCount()
	{ 
		$obj=new User_Model_Department();
		return $obj->getCount();
	}

	public static function create($row)
	{ 
		$obj=new User_Model_Department();
		return $obj->create($row);
	}

	public static function update($row,$ud_id)
	{ 
		$obj=new User_Model_Department();
		return $obj->update($row,$ud_id);
	}	

	public static function delete($id)
	{ 
		$obj=new User_Model_Department();
		return $obj->delete($id);
	}		
	
    public static function validator($val) {
        $error = array();
        $validateArr = array();
        $validateArr[] = array('name' => '部门名称', 'value' => $val['ud_name'], 'regex' => array('require', 'length[0,255]', ));
        $validateArr[] = array('name' => '排序序号', 'value' => $val['ud_sort'], 'regex' => array('positive'));
        $error = Common_Service_Validator::formValidator($validateArr);
        return $error;
    }
}